#include "OGLhelpers.h"
#include "constants.h"

int displayLists[8];

void switchTo2D()
{
	glMatrixMode(GL_PROJECTION);
	glPushMatrix();
	glLoadIdentity();
	glOrtho( -100.0f, 100.0f, -100.0f, 100.0f, -100.0f, 100.0f );
	//gluOrtho2D(0.0, SCR_WIDTH, SCR_HEIGHT, 0);
	glMatrixMode(GL_MODELVIEW);
	glPushMatrix();
	glLoadIdentity();
}

void switchTo3D()
{
	glMatrixMode(GL_PROJECTION);
	glPopMatrix();
	glMatrixMode(GL_MODELVIEW);
	glPopMatrix();
}

void createDispLists()
{
	displayLists[BLOCK] = glGenLists(1);
	glNewList(displayLists[BLOCK], GL_COMPILE);

	glPushMatrix();
	glBegin(GL_QUADS);
		glTexCoord2i(0, 0);
		glVertex3f(-1.0f, 1.0f, 0.0f);
		glTexCoord2i(1, 0);
		glVertex3f(1.0f, 1.0f, 0.0f);
		glTexCoord2i(1, 1);
		glVertex3f( 1.0f,-1.0f, 0.0f);
		glTexCoord2i(0, 1);
		glVertex3f(-1.0f,-1.0f, 0.0f);
	glEnd();
	glPopMatrix();

	glPushMatrix();
	glTranslatef(-1.0f, 0.0f, 1.0f);
	glRotatef(90, 0.0f, 1.0f, 0.0f);
	glBegin(GL_QUADS);
		glTexCoord2i(0, 0);
		glVertex3f(-1.0f, 1.0f, 0.0f);
		glTexCoord2i(1, 0);
		glVertex3f(1.0f, 1.0f, 0.0f);
		glTexCoord2i(1, 1);
		glVertex3f( 1.0f,-1.0f, 0.0f);
		glTexCoord2i(0, 1);
		glVertex3f(-1.0f,-1.0f, 0.0f);
	glEnd();
	glPopMatrix();

	glPushMatrix();
	glTranslatef(0.0f, 0.0f, 2.0f);
	glBegin(GL_QUADS);
		glTexCoord2i(0, 0);
		glVertex3f(-1.0f, 1.0f, 0.0f);
		glTexCoord2i(1, 0);
		glVertex3f(1.0f, 1.0f, 0.0f);
		glTexCoord2i(1, 1);
		glVertex3f( 1.0f,-1.0f, 0.0f);
		glTexCoord2i(0, 1);
		glVertex3f(-1.0f,-1.0f, 0.0f);
	glEnd();
	glPopMatrix();

	glPushMatrix();
	glTranslatef(1.0f, 0.0f, 1.0f);
	glRotatef(90.0f, 0.0f, 1.0f, 0.0f);
	glBegin(GL_QUADS);
		glTexCoord2i(0, 0);
		glVertex3f(-1.0f, 1.0f, 0.0f);
		glTexCoord2i(1, 0);
		glVertex3f(1.0f, 1.0f, 0.0f);
		glTexCoord2i(1, 1);
		glVertex3f( 1.0f,-1.0f, 0.0f);
		glTexCoord2i(0, 1);
		glVertex3f(-1.0f,-1.0f, 0.0f);
	glEnd();
	glPopMatrix();

	glEndList();
}